package com.example.mybatis.springbootdemo.service;

import com.alicp.jetcache.anno.CacheRefresh;
import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.example.mybatis.springbootdemo.contants.JetCacheNames;
import com.example.mybatis.springbootdemo.dao.daoService.UserDaoService;
import com.example.mybatis.springbootdemo.dao.entity.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * 作    者： yingming shen
 * 修改时间： 2020/8/16 10:53.
 * 描   述：
 */
@Service
@Slf4j
public class UserService {

    @Autowired
    private UserDaoService userDaoService;

    @Cached(name = JetCacheNames.name1 ,key = "#id", cacheType =CacheType.BOTH,timeUnit = TimeUnit.SECONDS,expire = 120)
    @CacheRefresh(refresh = 30, timeUnit = TimeUnit.SECONDS)
    public User getUser(Long id){
        return userDaoService.selectById(id);
    }

}
